//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
  //例如：import 《组件名称》 from '《组件路径》';
import { scrollMixin } from "utils/mixin";
export default {
  name:'',
  //import引入的组件需要注入到对象中才能使用
  components: { },
  mixins: [scrollMixin], //加载更多
  data() {
    return {
      active:'',
      tabList:[
        {
          name:'已抢购',
          status:''
        },
        {
          name:'待发放',
          status:0
        },
        {
          name:'已完成',
          status:1
        },
        // {
        //   name:'定制失败',
        //   status:2
        // }
      ],
      categoryTitle:'请选择分类',
      menuClass:false,
      // categoryName:'',
      page: 1,
      isLoadMore: true,
      total_page: 0,
      groupList:[],
      categoryList:[{
        id:'',
        category_name:'全部'
      }],
      categoryId:'',
      status:''
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    categoryClick() {
      this.menuClass = !this.menuClass;
    },
    categoryOn(item) {
      this.categoryId = item.id;
      this.categoryTitle = item.category_name;
      this.page = 1;
      this.menuClass = false;
      this.groupData();
    },
    takeTab(event) {
      this.status = event;
      this.page = 1;
      this.groupList = [];
      this.groupData();
    },
    toDetail(order) {
      this.$router.push(
        this.fun.getUrl("orderdetail", {
          order_id: order.id,
          isDetail: true,
          orderType: "customized-group"
        })
      );
    },
    polyIndex() {
      $http.post("plugin.customized-group.frontend.controllers.index.index", {}, "正在获取").then(
        response => {
          if (response.result == 1) {
            let res = response.data;
            let category = res.category;
            this.categoryList = [...this.categoryList,...category];
          } else {
            this.$dialog.alert({ message: response.msg });
          }
        },
        function(response) {
          // console.log(response);
          // error callback
        }
      );
    },
    groupData() {
      let query = {
        page:this.page,
        category_id:this.categoryId,
        status:this.status
      };
      $http.post('plugin.customized-group.frontend.controllers.group.join-group', query, "加载中..").then(response => {
        if (response.result == 1) {
            let res = response.data;
            let list = res.list.data;
            this.isLoadMore = true;
            this.total_page = res.list.last_page;
            if (!this.total_page) {
              this.page = 0;
            }
            this.groupList = list;
        } else {
          this.page = this.page - 1;
          this.isLoadMore = false;
          this.$dialog.alert({
            message: response.msg
          });
        }
      });
    },
    //获取更多数据
    getMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page = this.page + 1;
        let query = {
          page:this.page,
          category_id:this.categoryId,
          status:this.status
        };
        $http.post("plugin.customized-group.frontend.controllers.group.join-group", query, "加载中").then(
          res => {
            this.isLoadMore = true;
            if (res.result === 1) {
              let data = res.data;
              let list = data.list.data;
              this.groupList = [...this.groupList, ...list]; //数组拼接
            } else {
              this.page = this.page - 1;
              this.isLoadMore = false;
            }
          },
          function(response) {
            console.log("response", response);
            // error callback
          }
        );
      }
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {

  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {

  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {
    this.page = 1;
    this.categoryList = [{
      id:'',
      category_name:'全部'
    }];
    this.polyIndex();
    this.groupData();
  }, //如果页面有keep-alive缓存功能，这个函数会触发
  }